﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="get_test_by_time.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Class.get_test_by_time" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<body>
    <% 
        int id = int.Parse(Request.QueryString["id"]);
        DateTime date_from = DateTime.Parse(Request.QueryString["from"]);
        DateTime date_to = DateTime.Parse(Request.QueryString["to"]);
        var get_result = (from p in new TblResultController().FetchAll() orderby p.ResultId descending where p.ResultUser == id && DateTime.Parse(p.ResultDate.ToString()).Date >= date_from.Date && DateTime.Parse(p.ResultDate.ToString()).Date <= date_to.Date select p);
    %>
    <table class="w3-table w3-striped w3-bordered">
        <tr class="w3-teal">
            <th>Tên bài</th>
            <th>Ngày làm</th>
            <th>Hoàn thành</th>
            <th>Từ vựng</th>
            <th>Ngữ pháp</th>
            <th>Nghe</th>
            <th>Hán tự</th>
            <th>Tổng điểm</th>
            <th>&nbsp;</th>
        </tr>
        <%foreach (TblResult result in get_result)
          {
              var get_test = new TblTestController().FetchAll().Where(x => x.TestId == result.TestId).Single();

              if (get_test.TestExam != true)
                  continue;
              string result_user = result.ResultAnswer;
              int tuvung = 0, nguphap = 0, nghe = 0, hantu = 0;

              var get_tuvung = new TblTestDetailController().FetchAll().Where(x => x.TestId == get_test.TestId && x.TestDetailType == 1).ToList();
              var get_nguphap = new TblTestDetailController().FetchAll().Where(x => x.TestId == get_test.TestId && x.TestDetailType == 2).ToList();
              var get_nghe = new TblTestDetailController().FetchAll().Where(x => x.TestId == get_test.TestId && x.TestDetailType == 3).ToList();
              var get_hantu = new TblTestDetailController().FetchAll().Where(x => x.TestId == get_test.TestId && x.TestDetailType == 4).ToList();
              int td_count = new TblTestDetailController().FetchAll().Where(x => x.TestId == get_test.TestId).ToList().Count;
              float score = 100f / td_count;
              string[] split = new string[result_user.Split(',').Length];
              string[] split2 = new string[2];
              split = result_user.Split(',');
              for (int i = 0; i < result_user.Split(',').Length - 1; i++)
              {
                  split2 = split[i].Split('-');
                  int ok = 0;
                  var get_td = new TblTestDetailController().FetchAll().Where(x => x.TestDetailId == int.Parse(split2[0])).Single();
                  if (get_td.TestDetailConfirm == int.Parse(split2[1]))
                      ok = 1;
                  if (ok == 1)
                  {
                      if (get_td.TestDetailType == 1)
                          tuvung++;
                      else if (get_td.TestDetailType == 2)
                          nguphap++;
                      else if (get_td.TestDetailType == 3)
                          nghe++;
                      else if (get_td.TestDetailType == 4)
                          hantu++;
                  }
              }
              score = score * (tuvung + nguphap + nghe + hantu);
        %>
        <tr>
            <td><%=get_test.TestTitle%></td>
            <td><%=DateTime.Parse(result.ResultDate.ToString()).Day %>/<%=DateTime.Parse(result.ResultDate.ToString()).Month %>/<%=DateTime.Parse(result.ResultDate.ToString()).Year %></td>
            <td><%=result.ResultTime %>/<%=get_test.TestTime %> phút</td>
            <td><%=tuvung %>/<%=get_tuvung.Count %></td>
            <td><%=nguphap %>/<%=get_nguphap.Count %></td>
            <td><%=nghe %>/<%=get_nghe.Count %></td>
            <td><%=hantu %>/<%=get_hantu.Count %></td>
            <td><%=float.Parse(String.Format("{0:00.0}", score)) %></td>
            <td class="result-detail-btn"><a href="../Result.aspx?id=<%=result.ResultId %>" target="_blank" class="w3-text-teal">Chi tiết&nbsp;<i class="fa fa-angle-right"></i></a></td>
        </tr>
        <%} %>
    </table>
</body>
</html>
